package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kabuda
 * @create 2022-12-06 11:46
 */
@RestController
public class SendMessageController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg")
    public String sendMsg() {
        for (int i = 0; i < 10; i++) {
            //发送不同对象
            if (i % 2 == 0) {
                OrderEntity order = new OrderEntity();
                rabbitTemplate.convertAndSend("java-hello-exchange", "hello-java", order);
            } else {
                OrderItem orderItem = new OrderItem();
                rabbitTemplate.convertAndSend("java-hello-exchange", "hello-java", orderItem);
            }
        }
        return "ok";
    }
}
